/**
 * <copyright>
 * </copyright>
 *
 * $Id: SessionBeanImpl.java,v 1.1 2008/11/09 03:11:52 song Exp $
 */
package cn.edu.pku.sei.ra.wrapping.JOnAS.impl;

import javax.management.Attribute;
import javax.management.ObjectName;
import javax.management.j2ee.Management;

import cn.edu.pku.sei.ra.wrapping.JOnAS.JOnASPackage;
import cn.edu.pku.sei.ra.wrapping.JOnAS.SessionBean;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Session Bean</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link cn.edu.pku.sei.ra.wrapping.JOnAS.impl.SessionBeanImpl#getSessionTimeOut <em>Session Time Out</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SessionBeanImpl extends EJBImpl implements SessionBean {
	/**
	 * The default value of the '{@link #getSessionTimeOut() <em>Session Time Out</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSessionTimeOut()
	 * @generated
	 * @ordered
	 */
	protected static final int SESSION_TIME_OUT_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getSessionTimeOut() <em>Session Time Out</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSessionTimeOut()
	 * @generated
	 * @ordered
	 */
	protected int sessionTimeOut = SESSION_TIME_OUT_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SessionBeanImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return JOnASPackage.Literals.SESSION_BEAN;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getSessionTimeOut() {
		if(getCore()==null) return -1;
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			sessionTimeOut=((Integer)mainEntry.getAttribute(obj, "sessionTimeOut")).intValue();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sessionTimeOut;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void setSessionTimeOut(int newSessionTimeOut) {
		int oldSessionTimeOut = sessionTimeOut;
		sessionTimeOut = newSessionTimeOut;
		if(getCore()==null) return;
		Management mainEntry=JOnASPackage.eINSTANCE.getMainEntry();
		ObjectName obj=(ObjectName)getCore();
		
		try {
			Attribute ab=new Attribute(
					"sessionTimeOut",
					new Integer(newSessionTimeOut)
				);
			mainEntry.setAttribute(obj,ab);
			sessionTimeOut=newSessionTimeOut;
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, JOnASPackage.SESSION_BEAN__SESSION_TIME_OUT, oldSessionTimeOut, sessionTimeOut));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case JOnASPackage.SESSION_BEAN__SESSION_TIME_OUT:
				return new Integer(getSessionTimeOut());
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case JOnASPackage.SESSION_BEAN__SESSION_TIME_OUT:
				setSessionTimeOut(((Integer)newValue).intValue());
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case JOnASPackage.SESSION_BEAN__SESSION_TIME_OUT:
				setSessionTimeOut(SESSION_TIME_OUT_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case JOnASPackage.SESSION_BEAN__SESSION_TIME_OUT:
				return sessionTimeOut != SESSION_TIME_OUT_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (sessionTimeOut: ");
		result.append(sessionTimeOut);
		result.append(')');
		return result.toString();
	}

} //SessionBeanImpl
